#include <stdio.h>

int main() {
    // 遇到重复执行的语句可以使用循环解决问题

    int sum = 0;
    int count = 1;
    while (count <= 100) {
        sum += count;
        count++;
    }
    printf("sum = %d\n", sum);
    printf("\n");

    // while 与 do...while 唯一的区别就是:
    // do...while 会执行一次循环体然后再在执行判断(无条件执行一次循环体)
    // 而 while 先判断条件再执行循环体

    sum = 0;
    count = 1;
    do {
        sum += count;
        count++;

    } while (count <= 100);
    printf("sum = %d\n", sum);
    printf("\n");

    // for(A; B; C) D;
    // for 语句的执行顺序为: A -> B? -> C ->D B? -> C -> D...

    sum = 0;
    for (int i = 1; i <= 100; ++i) {
        sum += i;
    }
    printf("sum = %d\n", sum);
    printf("\n");

    // 循环和条件判断结合可以解决大部分的问题

    // 双重判断打印九九乘法表
    for (int i = 1; i <= 9; ++i) {
        for (int j = 1; j <= i; ++j) {
            printf("%d*%d=%d", j, i, i * j);
            if (j != 1 && i * j < 10) {
                printf(" ");
            }
            printf(" ");
        }
        printf("\n");
    }

    return 0;
}